package com.lgh.ibs.plugins.views;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

import com.lgh.ibs.constants.myenum.IbsMavenRootTypeEnum;
import com.lgh.ibs.constants.myenum.SnapshotOptionCodeEnum;
import com.lgh.ibs.constants.myenum.VersionOptionCodeEnum;
import com.lgh.ibs.entity.IbsRootMaven;
import com.lgh.ibs.entity.MavenPom;
import com.lgh.ibs.factory.IbsBeanFactory;
import com.lgh.ibs.log.IbsLogger;
import com.lgh.ibs.service.ProjectVersionManager;
import com.lgh.ibs.utils.ProjectFileUtil;

public class RootChildrenVersionView extends ViewPart {
	public static final String ID = "com.lgh.ibs.plugins.views.rootChildrenVersion"; //$NON-NLS-1$
	private Text workspace;
	private Table table;
	private boolean isAllSelectFlag = false; //表格中的复选框是否全部选中
	
	private TableColumn tcAllSelect;//表头全选组件
//	private Button ck_version;////当前版本筛复选框组件
//	private Button ck_parentVerion;//root版本复选框组件
	private Button buttonMax;//大需求按钮
	private Button buttonMix;//小需求按钮
	private Button buttonbug;//bug按钮
	private Button buttonVersionAdd_1;//版本号+1按钮
	private Button buttonVersionSub_1;//版本号-1按钮
	private Button buttonSave;//保存按钮
	private Button buttonReset;//重置按钮
	private Button buttonDelSnapshot;//去除Snapshot
	private Button buttonAddSnapshot;//添加Snapshot
	private String rootPomFilePath;
	
	private ProjectVersionManager projectVersionManager = IbsBeanFactory.getInstance(ProjectVersionManager.class);
	
	public RootChildrenVersionView() {
	}

	
	/**
	 * Create contents of the view part.
	 * @param parent
	 */
	public void createPartControl(final Composite container) {
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 10;
		container.setLayout(gridLayout);
		
		//工作空间输出目录
		Label workspaceOutDirLabel = new Label(container, SWT.CENTER);
//		GridData gridData_workspaceOutDirLable = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		GridData gridData_workspaceOutDirLable = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		workspaceOutDirLabel.setText("工作目录: ");
		gridData_workspaceOutDirLable.widthHint = 30;
		workspaceOutDirLabel.setLayoutData(gridData_workspaceOutDirLable);
		
		workspace = new Text(container, SWT.BORDER);
		GridData gd_workspace = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_workspace.heightHint = 25;
		workspace.setLayoutData(gd_workspace);
		gd_workspace.horizontalSpan = 8;
		String locationWorkSpace = Platform.getInstanceLocation().getURL().getPath();
		if(locationWorkSpace.startsWith("/")){
			locationWorkSpace = locationWorkSpace.substring(1, locationWorkSpace.length());
		}
		workspace.setText(locationWorkSpace);
		
		Button btnNewButton = new Button(container, SWT.LEFT);
		GridData gd_btnNewButton = new GridData(SWT.FULL_SELECTION, SWT.CENTER, true, false, 1, 1);
		btnNewButton.setText(" 浏览  ");
		btnNewButton.setLayoutData(gd_btnNewButton);
		
		// 添加按钮的选择事件
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				Shell shell = container.getShell();
				/*
				String fileName = new FileDialog(shell).open();
				if (fileName != null) {
					text.setText(fileName); 
				}*/
				//新建文件夹（目录）对话框
				DirectoryDialog folderdlg = new DirectoryDialog(shell);
				//设置文件对话框的标题
				folderdlg.setText("选择文件");
				//设置初始路径
				folderdlg.setFilterPath("SystemDrive");
				//设置对话框提示文本信息
				folderdlg.setMessage("请选择相应的文件夹");
				//打开文件对话框，返回选中文件夹目录
				String selecteddir=folderdlg.open();
				if(selecteddir==null){
					return ;
				}
				else{
					workspace.setText(selecteddir);
					IbsLogger.INFO("您选中的文件夹目录为: "+selecteddir);
					bandProjectImpData(selecteddir, container);
				}
				
			}
		});
		
		
//		URL imageURL = Platform.getBundle(Activator.PLUGIN_ID).getEntry("icons/bg.jpg");   
//		Image image = ImageDescriptor.createFromURL(imageURL).createImage();
		//操作类型
		Label lb_opType = new Label(container, SWT.CENTER);
		lb_opType.setText("选择");
		GridData gd_btn1 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		lb_opType.setLayoutData(gd_btn1);
		
		buttonMax = new Button(container, SWT.CHECK);
		buttonMax.setText("大需求");
		GridData gd_btn2 = new GridData(SWT.FULL_SELECTION, SWT.CENTER, true, false, 1, 1);
		buttonMax.setLayoutData(gd_btn2);
		
		buttonMix = new Button(container, SWT.CHECK);
		buttonMix.setText("小需求");
		GridData gd_btn3 = new GridData(SWT.FULL_SELECTION, SWT.CENTER, true, false, 1, 1);
		buttonMix.setLayoutData(gd_btn3);
		
		buttonbug = new Button(container, SWT.CHECK);
		buttonbug.setText("缺陷修复");
		GridData gd_btn4 = new GridData(SWT.FULL_SELECTION, SWT.CENTER, true, false, 1, 1);
		buttonbug.setLayoutData(gd_btn4);
		buttonbug.setSelection(true);
		
		Button temp1 = new Button(container, SWT.RADIO);
		GridData gd_btn5 = new GridData(SWT.FULL_SELECTION, SWT.CENTER, true, false, 1, 1);
		temp1.setLayoutData(gd_btn5);
		temp1.setVisible(false);
		
		Button temp2 = new Button(container, SWT.RADIO);
		GridData gd_btn6 = new GridData(SWT.FULL_SELECTION, SWT.CENTER, true, false, 1, 1);
		temp2.setLayoutData(gd_btn6);
		temp2.setVisible(false);
		
		Button temp3 = new Button(container, SWT.RADIO);
		GridData gd_btn7 = new GridData(SWT.FULL_SELECTION, SWT.CENTER, true, false, 1, 1);
		temp3.setLayoutData(gd_btn7);
		temp3.setVisible(false);
		
		Button temp4 = new Button(container, SWT.RADIO);
		GridData gd_btn8 = new GridData(SWT.FULL_SELECTION, SWT.CENTER, true, false, 1, 1);
		temp4.setLayoutData(gd_btn8);
		temp4.setVisible(false);
		
		Button temp5 = new Button(container, SWT.RADIO);
		GridData gd_btn9 = new GridData(SWT.FULL_SELECTION, SWT.CENTER, true, false, 1, 1);
		temp5.setLayoutData(gd_btn9);
		temp5.setVisible(false);
		
		Button temp6 = new Button(container, SWT.RADIO);
		GridData gd_btn10 = new GridData(SWT.FULL_SELECTION, SWT.CENTER, true, false, 1, 1);
		temp6.setLayoutData(gd_btn10);
		temp6.setVisible(false);
//		
		/***----------------------------------------------------------------------------------*/
		Label lb_op = new Label(container, SWT.CENTER);
		lb_op.setText("操作");
		GridData gd_op_btn1 = new GridData(SWT.FILL, SWT.LEFT, true, false, 1, 1);
		lb_op.setLayoutData(gd_op_btn1);
		
		
		buttonVersionAdd_1 = new Button(container, SWT.PUSH);
		buttonVersionAdd_1.setText("版本号+1");
		GridData gd_op_btn2 = new GridData(SWT.FULL_SELECTION, SWT.LEFT, true, false, 1, 1);
		buttonVersionAdd_1.setLayoutData(gd_op_btn2);
	
		buttonVersionSub_1 = new Button(container, SWT.PUSH);
		buttonVersionSub_1.setText("版本号-1");
		GridData gd_op_btn3 = new GridData(SWT.FULL_SELECTION, SWT.LEFT, true, false, 1, 1);
		buttonVersionSub_1.setLayoutData(gd_op_btn3);
		
		
		buttonAddSnapshot = new Button(container, SWT.PUSH);
		buttonAddSnapshot.setText("添加SNAPSHOT");
		GridData gd_op_btn4 = new GridData(SWT.FULL_SELECTION, SWT.LEFT, true, false, 1, 1);
		buttonAddSnapshot.setLayoutData(gd_op_btn4);
		
		buttonDelSnapshot = new Button(container, SWT.PUSH);
		buttonDelSnapshot.setText("去除SNAPSHOT");
		GridData gd_op_btn5 = new GridData(SWT.FULL_SELECTION, SWT.LEFT, true, false, 1, 1);
		buttonDelSnapshot.setLayoutData(gd_op_btn5);
		
		buttonSave = new Button(container, SWT.PUSH);
		buttonSave.setText("保存");
		GridData gd_op_btn6 = new GridData(SWT.FILL, SWT.LEFT, true, false, 1, 1);
		buttonSave.setLayoutData(gd_op_btn6);
		
		buttonReset = new Button(container, SWT.PUSH);
		buttonReset.setText("重置");
		GridData gd_op_btn7 = new GridData(SWT.FILL, SWT.LEFT, true, false, 1, 1);
		buttonReset.setLayoutData(gd_op_btn7);
		
		Text temp_1 = new Text(container, SWT.NONE);
		GridData gd_op_btn8 = new GridData(SWT.FILL, SWT.LEFT, true, false, 1, 1);
		temp_1.setLayoutData(gd_op_btn8);
		gd_op_btn6.horizontalSpan=3;
		
		
		//创建一个表
		createAndRsfushTable(container);
//		createActions();
//		initializeToolBar();
//		initializeMenu();
		//将数据绑定到表中
		bandProjectImpData(locationWorkSpace, container);
		//添加按钮事件处理
		tcAllSelect.addListener(SWT.Selection, new ProjectVersionListener());//表头全选组件
//		ck_version.addListener(SWT.Selection, new ProjectVersionListener());//当前版本筛复选框组件
//		ck_parentVerion.addListener(SWT.Selection, new ProjectVersionListener());//root版本复选框组件
		buttonMax.addListener(SWT.Selection, new ProjectVersionListener());//大需求按钮
		buttonMix.addListener(SWT.Selection, new ProjectVersionListener());//小需求按钮
		
		buttonbug.addListener(SWT.Selection, new ProjectVersionListener());//bug按钮
		buttonVersionAdd_1.addListener(SWT.Selection, new ProjectVersionListener());//版本号+1按钮
		
		buttonVersionSub_1.addListener(SWT.Selection, new ProjectVersionListener());//版本号-1按钮
		buttonSave.addListener(SWT.Selection, new ProjectVersionListener());//保存按钮
		buttonReset.addListener(SWT.Selection, new ProjectVersionListener());//重置按钮
		buttonAddSnapshot.addListener(SWT.Selection, new ProjectVersionListener());//添加SNAPSHOT
		buttonDelSnapshot.addListener(SWT.Selection, new ProjectVersionListener());//去除SNAPSHOT
		
	}
	
	private void createAndRsfushTable(final Composite container) {
		table = new Table(container, SWT.BORDER | SWT.FULL_SELECTION);
		GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_table.horizontalSpan = 10;
		table.setLayoutData(gd_table);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);

		String[] colNames = new String[] {"全选", "工程名称","工程类型", "当前版本", "修改版本"};
		tcAllSelect = new TableColumn(table, SWT.LEFT);
		tcAllSelect.setText(colNames[0]);
		
		TableColumn tcName = new TableColumn(table, SWT.LEFT);
		tcName.setText(colNames[1]);
		
		TableColumn projType = new TableColumn(table, SWT.NULL);
		projType.setText(colNames[2]);
		
		TableColumn version = new TableColumn(table, SWT.NULL);
		version.setText(colNames[3]);
		
		TableColumn editVersion = new TableColumn(table, SWT.NULL);
		editVersion.setText(colNames[4]);
		
		tcAllSelect.setWidth(50);
		tcName.setWidth(170);
		projType.setWidth(80);
		version.setWidth(150);
		editVersion.setWidth(150);
		
	}
	
	/**
	 * @Title: bandProjectImpData 
	 * @Description:绑定项目数据 
	 * @param button
	 * @param container
	 * @param progressBar 
	 * @throws 
	 * @author guohao.li
	 * @dateTime 2016年12月22日 下午3:38:34
	 */
	private void bandProjectImpData(String locationWorkSpace, final Composite container){
		Shell shell = container.getShell();
		if(locationWorkSpace == null || locationWorkSpace == ""){
			MessageDialog.openInformation(shell, "warning","工作空间不能为空");
			return ;
		}
		//获取数据，显示导入的项目信息
		File filePath = new File(locationWorkSpace);
		if(!filePath.exists()){
			MessageDialog.openInformation(shell, "warning","工作空间路径不存在,请手动选择一个路径");
		}
		
		table.clearAll();
		table.removeAll();
//		List<String> projectPomFilePathList = ProjectFileUtil.getProjectDir(locationWorkSpace);
		try {
			MavenPom mavenPom = ProjectFileUtil.getRootProjectPomFileInfo(locationWorkSpace);
			if(mavenPom != null){
				rootPomFilePath = mavenPom.getPomFilePath();
				List<IbsRootMaven> list = projectVersionManager.
						getRootProjectChildrenVersionList(mavenPom.getPomFilePath());
				for (IbsRootMaven maven : list) {
					//String[] colNames = new String[] {"全选", "工程名称","类型", "当前版本","修改版本"};
					
					TableItem item = new TableItem(table, SWT.NONE);
					item.setText(new String[] {"", maven.getProjectName(),
							IbsMavenRootTypeEnum.getName(maven.getProjectType()),
							maven.getProjectVersion(), "" });
					item.setData("projectType", maven.getProjectType());
				}
			}
			
		} catch (Exception e1) {
			e1.printStackTrace();
			IbsLogger.ERROR("获取pom.xml信息出错！", e1);
			MessageDialog.openInformation(shell, "warning","get pom.xml error！"+ e1.getMessage());
			return ;
		}
		
		
		TableItem[] items = table.getItems();
		for (int i = 0; i < items.length; i++) {
			// 第三列设置，创建TableEditor对象
			final TableEditor te_check = new TableEditor(table);
			// 创建一个文本框，用于输入文字
			final Button check_Btn = new Button(table, SWT.CHECK);
			// 将文本框当前值，设置为表格中的值
//			check_Btn.setText(items[i].getText(1));
			// 设置编辑单元格水平填充
			te_check.grabHorizontal = true;
			// 关键方法，将编辑单元格与文本框绑定到表格的第一列
			te_check.setEditor(check_Btn, items[i], 0);
			// 当文本框改变值时，注册文本框改变事件，该事件改变表格中的数据。
			// 否则即使改变的文本框的值，对表格中的数据也不会影响
			check_Btn.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent event) {
//					te_check.getItem().setText(1, "true");
//					te_check.getItem().setData("haoge");
//					System.out.println("---->: "+te_check.getItem().getText(3));
//					te_check.getItem().setData("name", "liguohao");
				}
			});
			items[i].setData("button_", check_Btn);
			
			// 第三列设置，创建TableEditor对象
			final TableEditor editorVersion = new TableEditor(table);
			// 创建一个文本框，用于输入文字
			final Text versionTextEdit = new Text(table, SWT.NONE);
			// 将文本框当前值，设置为表格中的值
			versionTextEdit.setText(items[i].getText(3));
			// 设置编辑单元格水平填充
			editorVersion.grabHorizontal = true;
			// 关键方法，将编辑单元格与文本框绑定到表格的第一列
			editorVersion.setEditor(versionTextEdit, items[i], 4);
			//设置值
			editorVersion.getItem().setText(3, versionTextEdit.getText());
			// 当文本框改变值时，注册文本框改变事件，该事件改变表格中的数据。
			// 否则即使改变的文本框的值，对表格中的数据也不会影响
			versionTextEdit.addModifyListener(new ModifyListener() {
				public void modifyText(ModifyEvent e) {
					editorVersion.getItem().setText(4, versionTextEdit.getText());
				}

			});
			items[i].setData("projectVersion_", versionTextEdit);
		
		}
	}

	/**
	 * Create the actions.
	 */
	private void createActions() {
		// Create the actions
	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		IToolBarManager toolbarManager = getViewSite().getActionBars()
				.getToolBarManager();
		Action action1 = new Action("新增") {
			public void run() {
			}
		};
		toolbarManager.add(action1);
	}

	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		IMenuManager menuManager = getViewSite().getActionBars()
				.getMenuManager();
	}

	public void setFocus() {
	}
	

	class ProjectVersionListener implements Listener{
		
		@Override
		public void handleEvent(Event event) {
			//如果 是表头全选
			if (event.widget == tcAllSelect) {
				TableItem[] items = table.getItems();
				for (int i = 0; i < items.length; i++) {
					Button btn = (Button) items[i].getData("button_");
					if(isAllSelectFlag){
						btn.setSelection(false);
					}else{
						
						btn.setSelection(true);
					}
				}
				//全选与取消全选
				isAllSelectFlag= !isAllSelectFlag;
				
				
			} else if (event.widget == buttonMax) {//大需求按钮
				boolean buttonMaxFalg = buttonMax.getSelection();
				boolean buttonMixFalg = buttonMix.getSelection();
				boolean buttonbugFalg = buttonbug.getSelection();
				if(!buttonMaxFalg && !buttonMixFalg && !buttonbugFalg){
					buttonMax.setSelection(true);
				}

			} else if (event.widget == buttonMix) {//小需求按钮
				boolean buttonMaxFalg = buttonMax.getSelection();
				boolean buttonMixFalg = buttonMix.getSelection();
				boolean buttonbugFalg = buttonbug.getSelection();
				if(!buttonMaxFalg && !buttonMixFalg && !buttonbugFalg){
					buttonMix.setSelection(true);
				}

			} else if (event.widget == buttonbug) {//bug按钮
				boolean buttonMaxFalg = buttonMax.getSelection();
				boolean buttonMixFalg = buttonMix.getSelection();
				boolean buttonbugFalg = buttonbug.getSelection();
				if(!buttonMaxFalg && !buttonMixFalg && !buttonbugFalg){
					buttonbug.setSelection(true);
				}

			} else if (event.widget == buttonVersionAdd_1) {//版本号+1按钮
				int itemCount = table.getItemCount();
				if(itemCount==0){
					MessageDialog.openInformation(buttonVersionAdd_1.getShell(), "信息","亲，当前没有数据可以操作哦！");
					return ;
				}
				versionAddOrSubOption(VersionOptionCodeEnum.Add_1.getCode());
				
			} else if (event.widget == buttonVersionSub_1) {//版本号-1按钮
				int itemCount = table.getItemCount();
				if(itemCount==0){
					MessageDialog.openInformation(buttonVersionSub_1.getShell(), "信息","亲，当前没有数据可以操作哦！");
					return ;
				}
				versionAddOrSubOption(VersionOptionCodeEnum.Sub_1.getCode());
				
			}else if (event.widget == buttonAddSnapshot) {//添加Snapshot
				int itemCount = table.getItemCount();
				if(itemCount==0){
					MessageDialog.openInformation(buttonAddSnapshot.getShell(), "信息","亲，当前没有数据可以操作哦！");
					return ;
				}
				snapshotAddOrDelOption(SnapshotOptionCodeEnum.Add.getCode());
				
			} else if (event.widget == buttonDelSnapshot) {//去除Snapshot
				int itemCount = table.getItemCount();
				if(itemCount==0){
					MessageDialog.openInformation(buttonDelSnapshot.getShell(), "信息","亲，当前没有数据可以操作哦！");
					return ;
				}
				snapshotAddOrDelOption(SnapshotOptionCodeEnum.Del.getCode());
				
			} else if (event.widget == buttonSave) {//保存按钮
				int itemCount = table.getItemCount();
				if(itemCount==0){
					MessageDialog.openInformation(buttonSave.getShell(), "信息","亲，当前没有数据可以保存哦！");
					return ;
				}
				
				saveTableItemModifyData();
					
			} else if (event.widget == buttonReset) {//重置按钮
				
			}
			
		}
		
		/**
		 * @Title: saveTableItemModifyData 
		 * @Description:保存表格中修改的数据 
		 * @throws 
		 * @author guohao.li
		 * @dateTime 2016年12月28日 上午11:14:48
		 */
		private void saveTableItemModifyData() {
			try {
				TableItem[] items = table.getItems();
				List<IbsRootMaven> list = new ArrayList<IbsRootMaven>();
				for (int i = 0; i < items.length; i++) {
					TableItem item = items[i];
					Button btn = (Button) item.getData("button_");
					boolean selection = btn.getSelection();
					if(selection){//选中的对版本号进行操作
						Text projectVersionText = (Text) item.getData("projectVersion_");
						String projectVersion = projectVersionText.getText();
						//pom文件路径
						String projectName = item.getText(1);
						Integer projectType = (Integer) item.getData("projectType");
						IbsRootMaven maven = new IbsRootMaven();
						maven.setProjectType(projectType);
						maven.setProjectName(projectName);
						maven.setProjectVersion(projectVersion);
						list.add(maven);
					}
				}
				projectVersionManager.saveRootPomSelectionData(list, rootPomFilePath);
				
				MessageDialog.openInformation(buttonSave.getShell(), "成功","版本号修改成功！");
			} catch (Exception e) {
				IbsLogger.ERROR("版本号操作出错！", e);
				MessageDialog.openError(buttonSave.getShell(), "错误","版本号操作出错，"+e.getMessage());
				return ;
			}
		}

		/**
		 * @Title: versionAddOrSubOption 
		 * @Description: 版本号增加 或减
		 * @param optionCode 操作码
		 * @throws 
		 * @author guohao.li
		 * @dateTime 2016年12月28日 上午11:14:02
		 */
		private void versionAddOrSubOption(Integer optionCode){
			try {
				TableItem[] items = table.getItems();
				for (int i = 0; i < items.length; i++) {
					TableItem item = items[i];
					Button btn = (Button) item.getData("button_");
					boolean selection = btn.getSelection();
					if(selection){//选中的对版本号进行操作
						Text projectVersionText = (Text) item.getData("projectVersion_");
						String projectVersion = projectVersionText.getText();
						
						IbsRootMaven maven = projectVersionManager.getRootProjectModifyVersionNumByParam(
								buttonMax.getSelection(), buttonMix.getSelection(),
								buttonbug.getSelection(),projectVersion, optionCode);
						//显示text控件
						if(maven.getProjectVersion() != null && maven.getProjectVersion() != ""){
							projectVersionText.setText(maven.getProjectVersion());
							item.setText(4, maven.getProjectVersion());
						}
						
					}
				}
			} catch (Exception e) {
				IbsLogger.ERROR("版本号操作出错！", e);
				MessageDialog.openError(buttonVersionAdd_1.getShell(), "错误","版本号操作出错，"+e.getMessage());
				return ;
			}
		}
		
		/**
		 * @Title: snapshotAddOrDelOption 
		 * @Description: 快照标签修改
		 * @param optionCode
		 * @throws 
		 * @author guohao.li
		 * @dateTime 2016年12月28日 上午11:15:16
		 */
		private void snapshotAddOrDelOption(Integer optionCode){
			try {
				TableItem[] items = table.getItems();
				for (int i = 0; i < items.length; i++) {
					TableItem item = items[i];
					Button btn = (Button) item.getData("button_");
					boolean selection = btn.getSelection();
					if(selection){//选中的对版本号进行操作
						Text projectVersionText = (Text) item.getData("projectVersion_");
						String projectVersion = projectVersionText.getText();
						
						IbsRootMaven maven = projectVersionManager.
								rootProjectSnapshotAddOrDelOption(projectVersion, optionCode);
						
						//显示text控件
						if(maven.getProjectVersion() != null && maven.getProjectVersion() != ""){
							projectVersionText.setText(maven.getProjectVersion());
							item.setText(4, maven.getProjectVersion());
						}
						
						
					}
				}
			} catch (Exception e) {
				IbsLogger.ERROR("版本号操作出错！", e);
				MessageDialog.openError(buttonVersionAdd_1.getShell(), "错误","SNAPSHOT版本号操作出错，"+e.getMessage());
				return ;
			}
		}
		
	}

}
